package com.yztc.orangeentertainment.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.facebook.drawee.view.SimpleDraweeView;
import com.yztc.orangeentertainment.R;
import com.yztc.orangeentertainment.base.OnItemClickListener;
import com.yztc.orangeentertainment.bean.starconbean.CategoryListBean;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by My on 2016/10/10.
 * 内容item adapter
 */
public class SubCategoryAdapter extends RecyclerView.Adapter<SubCategoryAdapter.MyViewHolder> {
    private List<CategoryListBean> list;
    private Context context;
    private OnItemClickListener listener;
    public void setList(List<CategoryListBean> list) {
        this.list = list;
    }
    public void setListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    public SubCategoryAdapter(Context context) {
        this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_star_news, null));
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        holder.tvStarNewsTitle.setText(list.get(position).getTitle());
        holder.tvStarNewsScanner.setText(list.get(position).getReadnum()+"");
        holder.tvStarNewsType.setText(list.get(position).getCat().getName());
        Glide.with(context).load(list.get(position).getCat().getIcon()).into(holder.ivStarNewsIcon);
        Glide.with(context).load(list.get(position).getPic()).into(holder.ivStarNewsPhoto);
        switch (list.get(position).getIcontype()){
            case 1:
                holder.iconType.setBackgroundResource(R.mipmap.icon_type_1);
                break;
            case 2:
                holder.iconType.setBackgroundResource(R.mipmap.icon_type_2);
                break;
            case 3:
                holder.iconType.setBackgroundResource(R.mipmap.icon_type_3);
                break;
            case 4:
                holder.iconType.setBackgroundResource(R.mipmap.icon_type_4);
                break;
            case 5:
                holder.iconType.setBackgroundResource(R.mipmap.icon_type_5);
                break;
            case 6:
                holder.iconType.setBackgroundResource(R.mipmap.icon_type_6);
                break;
            case 7:
                holder.iconType.setBackgroundResource(R.mipmap.icon_type_7);
                break;
            case 8:
                holder.iconType.setBackgroundResource(R.mipmap.icon_type_8);
                break;
            case 9:
                break;
            case 10:
                break;
            case 11:
                holder.iconType.setBackgroundResource(R.mipmap.icon_type_11);
                break;
            case 12:
                holder.iconType.setBackgroundResource(R.mipmap.icon_type_12);
                break;
        }
        if (listener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    listener.onItemClick(holder.itemView, pos);
                }
            });

            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int pos = holder.getLayoutPosition();
                    listener.onItemLongClick(holder.itemView, pos);
                    return false;
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.tv_star_news_title)
        TextView tvStarNewsTitle;
        @InjectView(R.id.iv_star_news_icon)
        ImageView ivStarNewsIcon;
        @InjectView(R.id.tv_star_news_type)
        TextView tvStarNewsType;
        @InjectView(R.id.tv_star_news_scanner)
        TextView tvStarNewsScanner;
        @InjectView(R.id.iv_star_news_photo)
        ImageView ivStarNewsPhoto;
        @InjectView(R.id.icon_type)
        SimpleDraweeView iconType;
        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }
}
